package ${package.Controller};

<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
import ${package.Service}.${table.serviceName};
import ${package.Entity}.${table.entityName};
import ${package.Entity?substring(0,package.Entity?last_index_of('.'))}.view.${entity}View;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import com.app.utils.Result;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * ${table.comment}
 *
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>
     @Autowired
     ${table.serviceName} ${table.serviceName?uncap_first};

    @RequiresPermissions("${entity}List")
    @RequestMapping(value = "/list.do", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> list(ServletRequest request, ServletResponse response, Page<${entity}View> page, ${entity}View view) {
        Map<String, Object> map = new HashMap<>();
        page.setDescs("id");
        List<${entity}View> list = ${table.serviceName?uncap_first}.get${entity}Views(page, view);
        map.put("records", list);
        map.put("total", page.getTotal());
        return map;
    }

    @RequiresPermissions("${entity}")
    @RequestMapping("/golist.do")
    public String tolist() {
        return "module/${entity?lower_case}/list";
    }

    @RequiresPermissions("Edit${entity}")
    @RequestMapping("/goEdit.do")
    public ModelAndView goEdit(${entity} entity) {
        Map<String, Object> map = new HashMap<>();
        if (entity.getId() != null) {
            entity = this.${table.serviceName?uncap_first}.selectById(entity.getId());
        }
        map.put("entity", entity);
        return new ModelAndView("module/${entity?lower_case}/edit", map);
    }

    @RequiresPermissions("Edit${entity}")
    @RequestMapping(value = "/save.do", method = RequestMethod.POST)
    @ResponseBody
    public Result save(${entity} entity) {
        boolean n = this.${table.serviceName?uncap_first}.insertOrUpdate(entity);
        return Result.returnResult(n);
    }

    @RequiresPermissions("Del${entity}")
    @RequestMapping(value = "/del.do", method = RequestMethod.POST)
    @ResponseBody
    public Result del(${entity} entity) {
        boolean n = this.${table.serviceName?uncap_first}.deleteById(entity.getId());
        return Result.returnResult(n);
    }

    @RequiresPermissions("Update${entity}")
    @RequestMapping(value = "/update.do", method = RequestMethod.POST)
    @ResponseBody
    public Result update(${entity} entity) {
        boolean n = this.${table.serviceName?uncap_first}.updateById(entity);
        return Result.returnResult(n);
    }
}

</#if>
